//
//  HMHomeViewController.m
//  HMSupplier
//
//  Created by haohao on 2017/7/3.
//  Copyright © 2017年 haohao. All rights reserved.
//

#import "HMHomeViewController.h"
#import "HMContactViewController.h"
#import "HMPeopleCenterViewController.h"
#import "HMOrderCenterViewController.h"
#import "BaseNaviViewController.h"

@interface HMHomeViewController ()

@end

@implementation HMHomeViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    [self addAllChildControllers];
}


- (void)addAllChildControllers
{
    
    BaseNaviViewController *navOrder = [self setChildView:[[HMOrderCenterViewController alloc] init] title:@"订单中心" imageName:@"orderCenter_ordercenter" selectedImageName:@"orderCenter_ordercenter_h"];
    BaseNaviViewController *navPeopleCenter = [self setChildView:[[HMPeopleCenterViewController alloc] init] title:@"个人中心" imageName:@"people_personalcenter" selectedImageName:@"people_personalcenter_h"];
    BaseNaviViewController *navContact = [self setChildView:[[HMContactViewController alloc] init] title:@"联系我们" imageName:@"conract_contactus" selectedImageName:@"conract_contactus_h"];
    NSArray *viewControllers = @[navOrder,navPeopleCenter,navContact];
    [self setViewControllers:viewControllers animated:YES];
}

- (BaseNaviViewController *)setChildView:(UIViewController *)childvc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName{
    BaseNaviViewController *navPeopleCenter = [[BaseNaviViewController alloc] initWithRootViewController:childvc];
    navPeopleCenter.navigationBarHidden = NO;
    navPeopleCenter.tabBarItem.title = title;
    childvc.title = title;
    navPeopleCenter.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    navPeopleCenter.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = kTabbarColor;
    textAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    [navPeopleCenter.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    
    NSMutableDictionary *selectedTextAttrs = [NSMutableDictionary dictionary];
    selectedTextAttrs[NSForegroundColorAttributeName] = kMainColor;
    [navPeopleCenter.tabBarItem setTitleTextAttributes:selectedTextAttrs forState:UIControlStateSelected];
    navPeopleCenter.tabBarItem.titlePositionAdjustment =UIOffsetMake(0, -5);
    
    return navPeopleCenter;
}

@end
